// cnpm install axios --save
// 1 引入axios  
import axios from 'axios'



//- 接口基准地址：`http://localhost:3000/api/`
// - 服务端已开启 CORS 跨域支持
// - API V1 认证统一使用 Token 认证
// - 需要授权的 API ，必须在请求头中使用 `Authorization` 字段提供 `token` 令牌
// - 使用 HTTP Status Code 标识状态
// - 数据返回格式统一使用 JSON 

let baseUrl = 'http://localhost:3000/api/'

axios.defaults.baseURL = baseUrl;
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// Add a request interceptor
// 请求拦截
let AUTH_TOKEN = window.localStorage.getItem('myToken') || ''
axios.interceptors.request.use(function(config) {
    // Do something before request is sent

    // console.log(config);
    if (config.url.includes('1106975712662')) {
        config.baseURL = 'http://localhost:3000/api/'

        config.headers['Authorization'] = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiYWRtaW4iLCJpYXQiOjE2Mzk1NjMwNTQsImV4cCI6MTYzOTU5OTA1NH0.ZKvAK7T-QzajcAtd3Q-5gCyrSxblLL95A8EEh7hFCdU'
    } else {
        config.baseURL = baseUrl
        config.headers['Authorization'] = AUTH_TOKEN; // 在发送请求之前在请求头配置token 
    }
    return config;
}, function(error) {
    // Do something with request error
    return Promise.reject(error);
});
// Add a response interceptor
// 响应拦截
axios.interceptors.response.use(function(response) {
    // Do something with response data
    // console.log(response);



    return response.data;

}, function(error) {
    // Do something with response error
    return Promise.reject(error);
});
// 封装统一api  
// 登录请求
// export let getLogin=(params)=>{
//     return axios.post('login',params)
// }

// 注册请求
export let getzuche = (params) => axios.post('user/register', params);
// // 登录请求
export let getLogin = (params) => axios.post('user/login', params);

// 搜素用户
export let getsousuo = (params) => axios.get(`user/search`, { params });
// 首页数据渲染
// 
// 购物车
export let Goods = (params) => axios.post('goods/add', params);
// 删除商品
export let delGoods = (params) => axios.delete('goods/del', { params });
// 获取商品列表
export let addGoods = (params) => axios.get('goods/lists', { params });
// 获取商品详情信息
export let addGoodMore = (params) => axios.get(`goods/more`, { params });
// 搜索商品
export let sousuoGood = (params) => axios.get(`goods/search`, { params });
// 修改商品
export let updateGood = (params) => axios.put(`goods/search`, params);
// 获取折扣(待定)
export let adddicount = (params) => axios.get(`goods/discount`, { params });
// 获取购物车列表
export let cartLists = (params) => axios.get(`cart/lists`, { params });
// 添加购物车
export let addcart = (params) => axios.post(`cart/add`, params);
// 删除购物车货物
export let delcart = (params) => axios.delete(`cart/del`, { params });
// 购物车商品数量修改
export let putnum = (params) => axios.put('cart/putnum', params);
// 发表品论
export let comments = (params) => axios.get(`comment/commentPost`, { params });
// 获取商品用户评论信息
export let comment = (params) => axios.post(`comment/Published`, params);
// 品质榜单数据渲染
//杂志数据渲染
export let magazineRouter = (params) => axios.get(`magazine/cover`, { params });
// 商家 获取商家简介信息 
export let business = (params) => axios.get(`business/lists`, { params });

// 获取商家详细信息的接口
export let getbuisne = (params) => axios.get('business/more', { params });
//添加口碑商家详细信息接口
export let getbuisnes = (params) => axios.post('business/add', params);
// 商家的点赞和踩接口
export let businessdian = (params) => axios.put("business/support", params);
//获取首页的商家分类
export let Godbusiness = (params) => axios.get("business/class", { params });

// 获取参加口碑活动的商家
export let shangjiabusiness = (params) => axios.get('business/activities', { params });
// 上传反馈
export let feedback = (params) => axios.post(`feedback/add`, params);

//获取反馈结果
export let getfeedback = (params) => axios.put("feedback/addover", params);

// 添加反馈列表
export let addfeedback = (params) => axios.get('feedback/lists', { params });

//添加反馈列表详情信息
export let addfeedgetOver = (params) => axios.get(`feedback/getOver`, { params })